package com.walker.demo.controller;


import com.walker.demo.annotation.DemoController;
import com.walker.demo.annotation.DemoRequestMapping;
import com.walker.demo.utils.View;
import com.walker.demo.utils.ViewData;
import com.walker.demo.utils.WebContext;

import javax.servlet.http.HttpServletRequest;

@DemoController
public class TestController {

    @DemoRequestMapping("toLogin")
    public View index(){
        System.out.println("toLogin...");
        //执行完forward1方法之后返回的视图
        return new View("/login.jsp");
    }

    /**
     * 处理登录请求,接受参数
     * @return
     */
    @DemoRequestMapping("login")
    public View login(){

        System.out.println("login...");

        //首先获取当前线程的request对象
        HttpServletRequest request = WebContext.requestHodler.get();

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        //将数据存储到ViewData中
        ViewData viewData = new ViewData();
        viewData.put("msg","欢迎你"+username);
        // 相当于
        // request.setAttribute("msg","欢迎你"+username);


        return new View("/index.jsp");
    }

}
